<?php
$article = new Models_Articles();
$content = $article->getArticle($id);
$subArticles = $article->getAllSubArticles($id);
$comments = $article->getAllComments($id);
$countComment = $article->countComment($id);
$tagsContent = new Models_Tags();
$tags = $tagsContent->getArticleTags($id);
?>
<div class="row">
    <div class="span7">
        <div class="well">
            <?php
                echo '<h4>' . $content['title'] . '</h4><br />';
                echo stripcslashes($content['body']);
            ?>
            <hr />
            <p class="" style="padding: 1px 1px; margin: -5px 0;;">
                   <i class="icon-calendar"></i> <?php echo $content['modified']; ?>
                  | <span class="label label-success"><i class="icon-comment icon-white"></i> <?php echo $countComment['count(id)']; ?></span>
                  | <i class="icon-tags"></i> Tags: 
                  <?php
                  foreach ($tags as $tag)
                  {
                      echo '<a href="/' . $tagsContent->path . 'articles/tag/' . $tag['id'] . '"><span class="label label-info">' . $tag['name'] . '</span></a> ';
                  }
                  ?>
            </p>
        </div>
        <?php if($content['comments']) { ?>
                <?php
                    if(count($comments) == 0)
                    {
                        echo '<div class="well">
                                    No comments. You could be the first.
                                    <a href="/' . $article->path . 'comment/add/' . $id . '" class="btn btn-info pull-right"><i class="icon-plus-sign"></i> Comment</a>
                                 </div>';
                    } else {
                         echo '<div class="well">
                                        <a href="/' . $article->path . 'comment/add/' . $id . '" class="btn btn-info pull-right"><i class="icon-plus-sign"></i> Comment</a>
                                     </div>';
                         echo '<script> 
                                        /* when document is ready */
                                        $(function() {
                                            /* initiate plugin */
                                            $("div.holder").jPages({
                                                containerID: "itemContainer"
                                            });
                                        });
                                    </script>';
                         echo '<ul id="itemContainer" class="list-no-bullet">';
                        foreach ($comments as $comment)
                        {
                            $userData = $article->getUserDataComment($comment['user_id']);
                            echo '<li><div class="alert alert-success"><h4 class="alert-heading">' 
                                    . $comment['title'] 
                                    . '</h4>' 
                                    . $comment['body'] 
                                    . '<hr />
                                        <p class="" style="padding: 1px 1px; margin: -5px 0;">
                                              <i class="icon-user"></i> <a href="#">' . $userData['login'] . ' (' . $userData['first_name'] . ' ' . $userData['second_name'] . ')</a> 
                                              | <i class="icon-calendar"></i> ' . $comment['created'] .
                                        '</p></div></li>';
                        }
                        ?>
                        </ul>
                        <!-- navigation panel -->
                        <div class="holder pagination">
                            <ul>
                                <li><a class="jp-previous jp-disabled">← previous</a></li>
                                <li><a class="jp-current">1</a></li>
                                <li><span class="jp-hidden">...</span></li>
                                <li> <a>2</a></li>
                                 <li><a>3</a></li>
                                 <li><a>4</a></li>
                                 <li><a>5</a></li>
                                 <li><a class="jp-hidden">6</a></li>
                                 <li><a class="jp-hidden">7</a></li>
                                 <li><a class="jp-hidden">8</a></li>
                                 <li><a class="jp-hidden">9</a></li>
                                 <li><span>...</span></li>
                                 <li><a>10</a></li>
                                <li><a class="jp-next">next →</a></li>
                            </ul>
                        </div>    
                        <?php
                    }
                   } else {  ?>
            <div class="well">
                Comments is disabled.
                <span class="btn btn-info disabled pull-right"><i class="icon-plus-sign"></i> Comment</span>
            </div>
        <?php } ?>
    </div>
    <div class="span2">
        <div class="well" style="padding: 8px 0;">
            <ul class="nav nav-list">
                <li class="active">
                    <a href="/<?php $article->printPath() ?>articles/show/<?php echo $id; ?>">
                        <?php echo $content['title']; ?>
                    </a>
                </li>
                <?php
                    foreach ($subArticles as $subArticle)
                    {
                        echo '<li>
                                <a class="" href="/' 
                                . $article->path 
                                . 'articles/showsub/' 
                                . $subArticle['id'] 
                                . '">' . $subArticle['title'] . '</a></li>';
                    } 
                ?>
            </ul>
        </div>
    </div>
</div>